package com.meituan.sqt.request.thirdpay;

import com.google.common.base.Preconditions;
import com.meituan.sqt.request.BaseApiRequest;
import com.meituan.sqt.utils.JsonUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: chenzhenfeng@meituan.com
 * @date: 2021/12/15 11:25
 * @description: 用于第三方平台对接商企通交易时进行自助联调测试
 */
@Data
public class ThirdPayMockRequest extends BaseApiRequest {
    /**
     * 自测方法
     */
    private String action;
    /**
     * 测试金额（根据方法判断是支付金额，退款金额）
     */
    private String amount;
    /**
     * 网关支付渠道类型
     */
    private Long tradeNo;
    /**
     * 业务类型，可以自行设置，如果未设置，则默认值为4（外卖）
     */
    private Integer businessType;
    /**
     * 扩展字段
     */
    private Map<String, Object> extInfoMap;

    /**
     * 创建请求，触发商企通调用第三方平台的下单接口
     * @param amount  订单金额
     * @param extInfoMap 可以为空，如果第三方希望携带扩展信息，可以自行填充
     * @return
     */
    public static ThirdPayMockRequest mockPay(String amount, Map<String, Object> extInfoMap) {
        Preconditions.checkArgument(extInfoMap != null && extInfoMap.size() > 0, "extInfoMap不允许为空");
        ThirdPayMockRequest request = new ThirdPayMockRequest();
        request.setAction("create");
        request.setAmount(amount);
        request.setExtInfoMap(extInfoMap);
        return request;
    }

    /**
     * 创建请求，触发商企通调用第三方平台的退款接口
     * @param amount
     * @param tradeNo
     * @return
     */
    public static ThirdPayMockRequest mockRefund(String amount, Long tradeNo) {
        ThirdPayMockRequest request = new ThirdPayMockRequest();
        request.setAction("refund");
        request.setAmount(amount);
        request.setTradeNo(tradeNo);
        return request;
    }

    /**
     * 创建请求，触发商企通调用第三方平台的支付查询接口
     * @param tradeNo
     * @return
     */
    public static ThirdPayMockRequest mockPayQuery(Long tradeNo) {
        ThirdPayMockRequest request = new ThirdPayMockRequest();
        request.setAction("query");
        request.setTradeNo(tradeNo);
        return request;
    }

    public static void main(String[] args) {
        Map<String, Object> extInfoMap = new HashMap<>();
        extInfoMap.put("staffId", 12L);
        extInfoMap.put("staffEmail", "chenzhenfeng");
        ThirdPayMockRequest request = ThirdPayMockRequest.mockPay("1.0", extInfoMap);

        String str = JsonUtil.object2Json(request);
        System.out.println(str);

        ThirdPayMockRequest request2 = JsonUtil.json2Object(str, ThirdPayMockRequest.class);
        System.out.println(str);
    }
}
